package com.baize.cpdepus.service.lmp;

import com.baize.cpdepus.common.R;
import com.baize.cpdepus.entity.Comment;
import com.baize.cpdepus.mapper.CommentMapper;
import com.baize.cpdepus.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//评论业务层实现
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public R<List<Comment>> lookAll(Integer current, Integer article) {
        List<Comment> comments = commentMapper.SelectAll(current, article);
        if (comments.isEmpty()) {
            return R.error("未查询到任何评论!");
        }
        return R.success(comments);
    }

    @Override
    public boolean insertOneUpVote(Comment comment) {
        try {
            commentMapper.InsertOneUpVote(comment);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
